home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / doom / ldhe-src.0 / ldhe-src / dehacked / source / conmode / conmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-15  |  2.1 KB  |  106 lines

  1.  
  2. /* This module handles all the VGA functions, for text mode switching,
  3.    font loading, etc.
  4. */
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/stat.h>
  8. #include <linux/vt.h>
  9. #include <signal.h>
  10. #include <termio.h>
  11. #include <stdio.h>
  12. #include <vga.h>
  13.  
  14. #include "8x8font.h"
  15. #include "8x16font.h"
  16.  
  17. void resize_vt(int cols, int rows)
  18. {
  19.     struct vt_sizes vtsize;
  20.     struct winsize win;
  21.     struct stat    st;
  22.  
  23.     vtsize.v_cols = cols;
  24.     vtsize.v_rows = rows;
  25.     vtsize.v_scrollsize = 0;
  26.  
  27.     (void) ioctl(2, VT_RESIZE, &vtsize);
  28.  
  29.     win.ws_row = rows;
  30.     win.ws_col = cols;
  31.     (void) ioctl(2, TIOCSWINSZ, &win);
  32.  
  33.     /* Check to see if /tmp/selection.pid exists */
  34.     if ( stat("/tmp/selection.pid", &st) == 0 ) {
  35.         /* If owned by root and only writable by root, */
  36.         if ( (st.st_uid == 0) && !(st.st_mode&022) ) {
  37.             /* Try to open the file and kill the selection pid */
  38.             FILE *pidfile;
  39.             if ( (pidfile=fopen("/tmp/selection.pid", "r")) ) {
  40.                 char buf[93]; int pid;
  41.                 if ( fgets(buf, 92, pidfile) && 
  42.                             (pid=atoi(buf)) ) {
  43.                     (void) kill(pid, SIGWINCH);
  44.                 }
  45.                 (void) fclose(pidfile);
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. void to_50lines(char *regs)
  52. {
  53.     regs[9]  = 0x47;
  54.     regs[10] = 0x06;
  55.     regs[11] = 0x07;
  56.     regs[12] = 0x00;
  57.     regs[13] = 0x00;
  58.  
  59.     vga_settextmoderegs(regs);
  60.     vga_puttextfont(font8x8_data);
  61.     vga_setmode(TEXT);
  62.     resize_vt(80, 50);
  63. }
  64.  
  65. void to_25lines(char *regs)
  66. {
  67.     regs[9]  = 0x4F;
  68.     regs[10] = 0x0D;
  69.     regs[11] = 0x0E;
  70.     regs[12] = 0x03;
  71.     regs[13] = 0x70;
  72.  
  73.     vga_settextmoderegs(regs);
  74.     vga_puttextfont(font8x16_data);
  75.     vga_setmode(TEXT);
  76.     resize_vt(80, 25);
  77. }
  78.  
  79.  
  80. main(int argc, char *argv[])
  81. {
  82.     struct vt_stat stats;
  83.     unsigned char regs[269];
  84.  
  85.     if ( ioctl(2, VT_GETSTATE, &stats) != 0 ) {
  86.         fprintf(stderr, "Not in a console.\n");
  87.         exit(255);
  88.     }
  89.  
  90.     /* Okay, we're in a console, initialize 50-line mode */
  91.     vga_disabledriverreport();
  92.     vga_setchipset(VGA);        /* avoid SVGA detection */
  93.     vga_init();
  94.     vga_setmode(TEXT);
  95.     vga_gettextmoderegs(regs);
  96.     switch (atoi(argv[1] ? argv[1] : "0")) {
  97.         case 50:    to_50lines(regs);
  98.                 break;
  99.         case 25:    to_25lines(regs);
  100.                 break;
  101.         default:    fprintf(stderr, "How many lines was that?\n");
  102.                 exit(1);
  103.     }
  104.     exit(0);
  105. }
  106.